package com.heima.controller;

import com.heima.pojo.entity.SkuClass;
import com.heima.pojo.dto.SkuClassSearchDto;
import com.heima.pojo.vo.SkuClassSearchVo;
import com.heima.service.SkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/vm-service/skuClass")
@Slf4j
@Api(tags = "商品类型相关接口")
public class SkuClassController {
    @Autowired
    private SkuClassService skuClassService;

    @PostMapping
    @ApiOperation("新增商品类型")
    public boolean add(@Validated @RequestBody SkuClass skuClass){
        skuClassService.addClass(skuClass);
        return true;
    }
    @GetMapping("/search")
    @ApiOperation("商品类型分页查询")
    public SkuClassSearchVo queryPage(SkuClassSearchDto skuClassSearchDto){
        return skuClassService.page(skuClassSearchDto);
    }

    @GetMapping("/{classId}")
    @ApiOperation("根据Id获取类型信息")
    public SkuClass selectById(@PathVariable String classId){
        return skuClassService.selectById(Integer.valueOf(classId));
    }

    @PutMapping("/{classId}")
    @ApiOperation("修改商品分类")
    public boolean update(@PathVariable String classId,@RequestBody SkuClass skuClass){
        skuClassService.update(Integer.valueOf(classId),skuClass);
        return true;
    }

    @DeleteMapping("/{classId}")
    @ApiOperation("删除商品类型")
    public void delById(@PathVariable String classId){
        skuClassService.delById(classId);
    }
}
